package leetcode;
/*
http://www.ruanyifeng.com/blog/2013/05/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm.html
kmp算法介绍
 */
public class Test0028 {
    public int strStr(String haystack, String needle) {
        if(needle==null || needle.length()==0 )
            return 0;
        if(haystack.length()<needle.length())
            return -1;
        for(int i=0;i<=haystack.length()-needle.length();i++){
            if(haystack.charAt(i)!=needle.charAt(i))
                continue;
            if(haystack.substring(i,i+needle.length()).equals(needle)){
                return i;
            }
        }

        return -1;
    }
}
